home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Fritz: All Fritz
/
All Fritz.zip
/
All Fritz
/
FILES
/
PROGMISC
/
FPCDOCS.LZH
/
SAVEREST.SEQ
< prev
next >
Wrap
Text File
|
1988-09-20
|
2KB
|
80 lines
\ SAVEREST.SEQ Save and restore words for variables or values.
FILES DEFINITIONS
VARIABLE SAVEREST.SEQ
FORTH DEFINITIONS META IN-META
comment:
These words allow you to quickly save the contents of a
variable of value on the return stack, and set it to some other
value temporarily with SAVE!>. The previous contents may then
be restored with RESTORE>.
Here is an example, first the old way:
VARIABLE MYSTUFF
: DEF ( --- )
32 MYSTUFF DUP @ >R !
... Do something with the new MYSTUFF ...
R> MYSTUFF ! ;
Here is an example of how to use SAVE!> and RESTORE>:
: DEF ( --- )
32 SAVE!> MYSTUFF
... Do something with the new MYSTUFF ...
RESTORE> MYSTUFF ;
comment;
CODE %SAVE!> ( N1 --- )
LODSW ES:
MOV BX, AX
ADD BX, # 3
SUB RP, # 2
MOV AX, 0 [BX]
MOV 0 [RP], AX
POP 0 [BX]
NEXT END-CODE
CODE %SAVE> ( --- )
LODSW ES:
MOV BX, AX
SUB RP, # 2
MOV AX, 3 [BX]
MOV 0 [RP], AX
NEXT END-CODE
CODE %RESTORE> ( --- )
PUSH 0 [RP]
ADD RP, # 2
LODSW ES:
MOV BX, AX
POP 3 [BX]
NEXT END-CODE
: ?COMP ( --- )
STATE @ 0= ABORT" Use only while compiling" ;
\ the following word does the equivalent of "VARIABLE-NAME DUP @ >R !"
\ Leaves value in T1 on return stack
: SAVE!> ( N1 T1 --- ) \ and sets body of t1 to n1.
?COMP COMPILE %SAVE!> ; IMMEDIATE
\ This one does "VARIABLE-NAME @ >R"
: SAVE> ( T1 --- ) \ Saves value in T1 body on return stack.
?COMP COMPILE %SAVE> ; IMMEDIATE
\ This does "R> VARIABLE-NAME !"
: RESTORE> ( T1 --- ) \ Restore body of T1 from return stack.
?COMP COMPILE %RESTORE> ; IMMEDIATE